{include file="public/toper" /}
<div class="layui-tab layui-tab-brief main-tab-container">
    <ul class="layui-tab-title main-tab-title">
        <span class="main-tab-item">附件管理</span>
    </ul>
    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show" style="min-height: 500px">

            <form class="layui-form" method="get">

                <table class="layui-table">
                    <thead>
                    <tr>
                        <th style="width: 2%">ID</th>
                        <th style="width: 3%">文件名称</th>
                        <th style="width: 6%">文件大小</th>
                        <th>
                            文件路径
                        </th>
                        <th style="width: 15%">
                            上传时间
                        </th>
                        <th style="text-align: center;width: 5%" >
                            状态
                        </th>
                        <th style="text-align: center;width: 5%">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                        {notempty name="$data"}
                            {foreach name="$data" id="da"}
                                <tr>

                                    <td>{$da['id']}</td>
                                    <td>{$da['filename']}</td>
                                    <td>
                                        {if condition="round($da['file_size']/1024,2) gt 1024"}
                                            {:round(round($da['file_size']/1024,2)/1024,2)} MB
                                        {else /}
                                            {:round($da['file_size']/1024,2)} KB
                                        {/if}

                                    </td>
                                    <td>
                                        {if condition="strlen($da['file_path']) > 20"}
                                        {:mb_substr($da['file_path'],0,20)}...&nbsp;<span class="layui-btn layui-btn-xs" onclick='layer.alert("{:htmlspecialchars($da.file_path)}")'>查看</span>
                                        {else /}
                                        {$da['file_path']}
                                        {/if}
                                    </td>
                                    <td>{$da['create_time']}</td>
                                    <td>
                                        {if condition="$da['status'] eq 1"}
                                            正常
                                            {else /}
                                            未知
                                        {/if}
                                    </td>

                                    <td style="text-align: center;">
                                        待定
                                    </td>
                                </tr>
                            {/foreach}
                        {/notempty}
                    </tbody>
                    <thead>
                        <tr>
                            <th colspan="3">

                            </th>
                            <th colspan="6"><div id="page">{$page}</div></th>
                        </tr>
                    </thead>

                </table>
            </form>


        </div>
    </div>
</div>

<script type="text/javascript">
    layui.use(['element', 'layer', 'form' ,'upload' ,'laypage'], function(){
        var element = layui.element
                ,jq = layui.$
                ,form = layui.form
                ,laypage = layui.laypage
                ,upload = layui.upload;
        //ajax删除单个内容
        jq('.del_btn').click(function(){
            var name = jq(this).attr('article-name');
            var id = jq(this).attr('article-id');
            layer.confirm('确定删除【'+name+'】?', function(index){
                loading = layer.load(2, {
                    shade: [0.2,'#000'] //0.2透明度的白色背景
                });
                jq.post(
                    '{:url("isDel")}',
                    {'id':id},
                    function(data){
                        if(data.code == 200){
                            layer.close(loading);
                            layer.msg(data.msg, {icon: 1, time: 1000}, function(){
                                location.reload();//do something
                            });
                        }else{
                            layer.close(loading);
                            layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
                        }
                    }).error(function () {
                        layer.close(loading);
                        layer.msg('服务器错误', {icon: 2, anim: 6, time: 1000});
                });

            });

        });
        //全选
        form.on('checkbox(checkAll)', function(data){
            if(data.elem.checked){
                jq("input[type='checkbox']").prop('checked',true);
            }else{
                jq("input[type='checkbox']").prop('checked',false);
            }
            form.render('checkbox');
        });
        //选择一个
        form.on('checkbox(checkOne)', function(data){
            var is_check = true;
            if(data.elem.checked){
                jq("input[lay-filter='checkOne']").each(function(){
                    if(!jq(this).prop('checked')){ is_check = false; }
                });
                if(is_check){
                    jq("input[lay-filter='checkAll']").prop('checked',true);
                }
            }else{
                jq("input[lay-filter='checkAll']").prop('checked',false);
            }
            form.render('checkbox');
        });



    });

</script>
</body>
</html>